package com.chen.handler;

import com.chen.common.MyExpection;
import com.chen.common.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.rmi.ServerException;

/**
 * ClassName: GlobalExpectionHandler
 * Package: com.chen.handler
 * Description: 全局异常处理器
 *
 * @Author 陈俊辉
 * @Create 2024/4/11 1:23
 * @Version 1.0
 */
@RestControllerAdvice
public class GlobalExpectionHandler {

    @ExceptionHandler(MyExpection.class)
    public Result errorAction(MyExpection myExpection){
        return Result.error(myExpection.getErrorCode());
    }


    @ExceptionHandler(ServerException.class)
    @ResponseBody
    public Result doAction(Exception e){
        String message = e.getMessage();
        return Result.error(message);
    }
}
